import PropTypes from 'prop-types'
import DescriptionList from '@/components/DescriptionList'
import * as G from '@/utils/common'
import * as R from 'ramda'

const { Description } = DescriptionList


// 东风车主详情
const DFPVOwerProfile = ({ user }, { dicData }) => {
  const {
    userName, sexuality, idType, idNo, mobilePhone, email, createDate,
  } = user

  const translate = (code, key) => R.ifElse(
    G.isEmptyOrNil,
    R.always(''),
    R.compose(
      G.getDicByKey(dicData, code),
      R.toString
    )
  )(key)

  return (
    <DescriptionList title="车主信息" col={3} style={{ marginBottom: 16 }}>
      <Description term="姓名">{userName}</Description>
      <Description term="性别"> {translate('sex', sexuality)}</Description>
      <Description term="证件类型"> {translate('idType', idType)}</Description>
      <Description term="证件号">{idNo}</Description>
      <Description term="手机">{mobilePhone}</Description>
      <Description term="邮箱">{email}</Description>
      <Description term="注册时间">{createDate ? G.dateFormatHMS(createDate) : ''}</Description>
    </DescriptionList>
  )
}
DFPVOwerProfile.contextTypes = {
  dicData: PropTypes.any,
}

// 北汽车主详情（多了紧急联系人和紧急联系人电话两个字段）
const BAICOwerProfile = ({ user }, { dicData }) => {
  const {
    userName, sexuality, idType, idNo, mobilePhone, email, createDate,contract,contractPhone
  } = user

  const translate = (code, key) => R.ifElse(
    G.isEmptyOrNil,
    R.always(''),
    R.compose(
      G.getDicByKey(dicData, code),
      R.toString
    )
  )(key)

  return (
    <DescriptionList title="车主信息" col={3} style={{ marginBottom: 16 }}>
      <Description term="姓名">{userName}</Description>
      <Description term="性别"> {translate('sex', sexuality)}</Description>
      <Description term="证件类型"> {translate('idType', idType)}</Description>
      <Description term="证件号">{idNo}</Description>
      <Description term="手机">{mobilePhone}</Description>
      <Description term="邮箱">{email}</Description>
      <Description term="注册时间">{createDate ? G.dateFormatHMS(createDate) : ''}</Description>
      <Description term="紧急联系人">{contract}</Description>
      <Description term="紧急联系人电话">{contractPhone}</Description>
    </DescriptionList>
  )
}
BAICOwerProfile.contextTypes = {
  dicData: PropTypes.any,
}

// 车主详情
const OwerProfile = ({ user, brandId }) => {
  const profileMap = new Map([
    ['DFPV', <DFPVOwerProfile user={user} />],
    ['HAIMA', <DFPVOwerProfile user={user} />],
    ['PEUGEOT', <DFPVOwerProfile user={user} />],
    ['DCAD', <DFPVOwerProfile user={user} />],
    ['SINOMACH', <DFPVOwerProfile user={user} />],
    ['BAIC', <BAICOwerProfile user={user} />],
    ['SGMW', <BAICOwerProfile user={user} />],
    ['BJEV', <BAICOwerProfile user={user} />],
  ])
  return profileMap.get(brandId) ? profileMap.get(brandId) : <DFPVOwerProfile user={user} />
}

export default OwerProfile
